package com.whale.kernel.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.whale.kernel.domain.Keyable;

public class KeyableDataUtils {

	public static <T extends Keyable> List<Long> transformToKeyList(
			List<T> keyableList) {
		List<Long> keys = new ArrayList<Long>();
		for (T item : keyableList) {
			keys.add(item.getId());
		}
		return keys;
	}

	public static <T extends Keyable> Set<Long> transformToKeySet(
			Set<T> keyableSet) {
		Set<Long> keys = new HashSet<Long>();
		for (T item : keyableSet) {
			keys.add(item.getId());
		}
		return keys;
	}

	public static <T extends Keyable> Set<Long> transformListToKeySet(
			List<T> keyableList) {
		Set<Long> keys = new HashSet<Long>();
		for (T item : keyableList) {
			keys.add(item.getId());
		}
		return keys;
	}

	public static List<Long> reverseSort(Set<Long> keySet) {
		List<Long> revs = new ArrayList<Long>(keySet);
		Collections.sort(revs, new Comparator<Long>() {
			public int compare(Long o1, Long o2) {
				return (-1) * o1.compareTo(o2);
			}
		});

		return revs;
	}
}
